import { BasicColumn, FormSchema } from '/@/components/Table';
import { rules } from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import { DescItem } from '/@/components/Description/index';
import { formatToDateTime } from '/@/utils/dateUtil';

const getRefundStatusColor = (text) => {
  let color = 'green'
  if (text === '10') color = 'purple'
  if (text === '12') color = 'gold'
  if (text === '13') color = 'green'
  if (text === '16') color = 'red'
  if (text === '17') color = 'pink'
  if (text === '18') color = 'orange'  
  return color
}
export const columns: BasicColumn[] = [
  {
    title: '支付金额',
    width: 80,
    dataIndex: 'payAmount',
    customRender: ({text}) => {
      return text + '元'
    }
  },
  {
    title: '支付方式',
    width: 130,
    dataIndex: 'wayCodeValue'
  },
  {
    title: '退款金额',
    width: 80,
    dataIndex: 'refundAmount',
    customRender: ({text}) => {
      return text + '元'
    }
  },
  {
    title: '退款订单号',
    width: 180,
    dataIndex: 'refundOrderNo',
    slots: { customRender: 'refundOrderNo' }
  },

  {
    title: '支付订单号',
    width: 180,
    dataIndex: 'payOrderNo',
    slots: { customRender: 'payOrderNo' }
  },

  {
    title: '退款状态',
    width: 90,
    dataIndex: 'status',
    customRender: ({text}) => {
      let color = getRefundStatusColor(text)
      return render.renderTag(render.renderDict(text, 'pay_refund_status'), color)
    }
  },
  {
    title: '创建时间',
    width: 150,
    customRender: ({text}) => {
      return formatToDateTime(Number(text))
    },
    dataIndex: 'createdAt',
  }
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'unionOrderNo',
    label: '订单号',
    component: 'Input',
    colProps: {span: 6},
    componentProps: {
      placeholder:'支付/退款订单号'
    },
  },
  {
    field: 'mchNo',
    label: '商户号',
    component: 'Input',
    colProps: {span: 6}
  },
  {
    field: 'appId',
    label: '应用APPID',
    component: 'Input',
    colProps: {span: 6}
  },
  {
    label: '退款状态',
    field: 'refundStatus',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'pay_refund_status',
      placeholder:'请选择退款状态'
    },
    colProps: {span: 6},
  },
  {
    label: '商户类型',
    field: 'mchType',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode:'mch_type',
      placeholder:'请选择商户类型'
    },
    colProps: {span: 6},
  },
  {
    field: 'fieldTime',
    component: 'RangePicker',
    label: '创建时间',
    componentProps: {
      valueType: 'Date',
    },
    colProps: { span: 6},
  },
];


export const formDetailSchema : DescItem[]= [
  {
    field: 'mchTypeValue',
    label: '所属系统',
    span: 2
  },
  {
    field: 'isvNo',
    label: '服务商号',
    span: 2
  },
  {
    field: 'refundOrderId',
    label: '退款订单号',
    span: 2
  },
  {
    field: 'mchNo',
    label: '商户号',
    span: 2
  },
  {
    field: 'payOrderNo',
    label: '支付订单号',
    span: 2
  },
  {
    field: 'mchRefundNo',
    label: '商户退款单号',
    span: 2
  },
  {
    field: 'channelPayOrderNo',
    label: '渠道支付订单号',
    span: 2
  },
  {
    field: 'appId',
    label: '应用APPID',
    span: 2
  },
  {
    field: 'payAmount',
    label: '支付金额',
    render: (curVal, data) => {
      let color = 'green'
      if (!curVal) {
        curVal = 0
      }
      return render.renderTag(curVal, color)
    },
    span: 2
  },
  {
    field: 'refundAmount',
    label: '退款金额',
    render: (curVal, data) => {
      let color = 'green'
      if (!curVal) {
        curVal = 0
      }
      return render.renderTag(curVal, color)
    },
    span: 2
  },
  {
    field: 'status', 
    label: '退款状态',
    render: (curVal, data) => {
      let color = getRefundStatusColor(curVal)
      return render.renderTag(render.renderDict(curVal, 'pay_refund_status'), color)
    },
    span: 2
  },
  {
    field: 'refundReason',
    label: '退款原因',
    span: 2
  },
  {
    field: 'successTime',
    label: '退款成功时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 2
  },
  {
    field: 'expiredTime',
    label: '退款超时时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 2
  },
  {
    field: 'createdAt',
    label: '创建时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 2
  },
  {
    field: 'updatedAt',
    label: '更新时间',
    render: (curVal, data) => {
      return formatToDateTime(Number(curVal))
    },
    span: 12
  },
  {
    field: 'divider',
    label: '',
    render: (curVal, data) => {
      return render.renderDivider()
    },
    span: 12
  },
  {
    field: 'ifCode',
    label: '接口代码',
    span: 2
  },
  {
    field: 'currency',
    label: '货币代码',
    span: 2
  },
  {
    field: 'wayCode',
    label: '方式代码',
    span: 2
  },
  {
    field: 'clientIp',
    label: '客户端IP',
    span: 2
  },
  {
    field: 'notifyUrl',
    label: '异步通知地址',
    span: 12
  },

  {
    field: 'divider',
    label: '',
    render: (curVal, data) => {
      return render.renderDivider()
    },
    span: 12
  },
  {
    field: 'channelOrderNo',
    label: '渠道订单号',
    span: 2,
  },
  {
    field: 'errCode',
    label: '渠道错误码',
    span: 2,
  },
  {
    field: 'errMsg',
    label: '渠道错误描述',
    span: 12,
  },
  {
    field: 'channelExtra',
    label: '渠道额外参数',
    span: 12,
  },

  {
    field: 'divider',
    label: '',
    render: (curVal, data) => {
      return render.renderDivider()
    },
    span: 12
  },
  {
    field: 'extParam',
    label: '扩展参数',
    span: 12
  },
  {
    field: 'remark',
    label: '备注',
    span: 12
  },
];
